package com.qfedu.dao;

import com.qfedu.model.Item;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.Date;
import java.util.List;

public interface ItemDao {

    //添加
    @Insert("insert into item (iname,starttime,endtime,suid,updatetime,status) values(" +
            "#{iname},#{starttime},#{endtime},#{suid},#{updatetime},#{status})")
    void addItem(Item item);

    //删除
    @Update("update item set status = 0 where iid=#{iid}")
    void deleteItem(String iid);

    //修改
    @Update("update item set iname=#{iname},starttime=#{starttime},endtime=#{endtime},suid=#{suid}," +
            "updatetime=#{updatetime},status=#{status} where iid = #{iid}")
    void updateItem(Item item);

    //根据suid查询
    @Select("select * from item where status = 1 and suid = #{suid}")
    List<Item> findBySuid(String suid);

    //查询所有
    @Results(id = "findAllMap",value = {
            @Result(column = "iid",property = "iid"),
            @Result(column = "iname",property = "iname"),
            @Result(column = "starttime",property = "starttime"),
            @Result(column = "endtime",property = "endtime"),
            @Result(column = "suid",property = "suid"),
            @Result(column = "updatetime",property = "updatetime"),
            @Result(column = "status",property = "status"),
            @Result(column = "suid",property = "subitems",
                    one = @One(select = "com.qf.dao.SubitemDao.findBySuid",fetchType = FetchType.EAGER))
    })
    @Select("select * from item where status = 1")
    List<Item> findAll();
}